package com.controller;

import com.common.Result;
import com.entity.Comment;
import com.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * User的路由接口服务
 * 
 * @author 
 *
 */
@RestController
@RequestMapping("pcApi")
public class CommentController {

	/** UserService服务 */
	@Autowired
	private CommentService commentService;

	/**
	 * 通过id查询User数据的方法
	 * @param id
	 * @return
	 */
	@ResponseBody
	@GetMapping(value = "/comment/{id}", produces = {"application/json;charset=UTF-8"})
	public Comment findOne(@PathVariable(name="id") int id) {
		return commentService.findOne(id);
	}

	/**
	 * 通过articleId查找评论
	 * @param articleId
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/comment/index/{articleId}", produces = {"application/json;charset=UTF-8"})
	public Result indexByArticleId(@PathVariable(name="articleId") int articleId){
		return commentService.findAllByArticleId(articleId);
	}

	/**
	 * 发表评论
	 * @param comment
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/comment/create", produces = {"application/json;charset=UTF-8"})
	public Result create(@RequestBody Comment bean){
		return commentService.create(bean);
	}



}
